package com.example.boot.controller;

import com.example.common.Result;
import com.example.pojo.entity.RouteItem;
import com.example.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author ding
 * @since 2024/7/2
 */
@RestController
@Slf4j
@Api(tags = "菜单接口")
public class MenuController {

    @Autowired
    private MenuService menuService;


    @ApiOperation("获取菜单信息  左侧菜单栏使用")
//    @PreAuthorize("hasAuthority('MENU_LIST')")
    @GetMapping("/getMenuList")
    public Result getAllMenu(){
       List<RouteItem> routeItemList = menuService.getAllMenu();
        return Result.success(routeItemList);
    }

    @ApiOperation("上传菜单信息")
//    @PreAuthorize("hasAuthority('MENU_SUBMIT')")
    @PostMapping("/submitMenu")
    public Result sumbit(@RequestBody RouteItem routeItem){
        //上传菜单
        menuService.sumbitMenu(routeItem);

        return Result.success();
    }

    @ApiOperation("根据id删除菜单信息")
//    @PreAuthorize("hasAuthority('MENU_DELETE')")
    @DeleteMapping("/deleteMenu/{id}")
    public Result deleteMenu(@ApiParam("菜单id") @PathVariable Integer id) {
        menuService.deleteMenu(id);
        return Result.success();
    }

}
